<?php
require_once ('Config.php');
/* require_once ('storage.php');
require_once ('authHelper.php');

$storage = new apiSessionStorage();
$authHelper = new AuthHelper($client, $storage, 'index.php');


if ($authHelper->isAuthorized()) {
	$authHelper->revokeToken();
	$analytics = new Google_Service_Analytics($client);
} else if(isset ($_GET['code'])) {
	$authHelper->authenticate();
} else {
	$authHelper->setTokenFromStorage();
}

$storage->set($client->getAccessToken()); */

if (isset($_GET['code'])) {
        
    	$client->authenticate($_GET['code']);  
    	$_SESSION['token'] = $client->getAccessToken();
		print_r ($client->getAccessToken());
    	$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    	header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
		
    }
	else {
	$authUrl = $client->createAuthUrl();
	
	}

	
if (isset($_SESSION['token'])) {
		$client->setAccessToken($_SESSION['token']);
		//$_SESSION['client']= $client;
		$analytics = new Google_Service_Analytics($client);
		$plus = new Google_Service_Oauth2($client);
		$accounts = $analytics->management_accountSummaries->listManagementAccountSummaries();
		//$_SESSION['accounts']= $accounts;
		
	}
if (isset($_REQUEST['logout'])) {
unset($_SESSION['token']);
}
$coba = $client->getRefreshToken();

echo $coba;



 

